package se.penselnsvag.bookdb.unittest
{
	import flash.display.DisplayObject;
	
	import flexunit.framework.TestCase;
	
	import mx.controls.Alert;
	import mx.core.Application;
	import mx.managers.PopUpManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	import se.penselnsvag.bookdb.module.user.User;
	import se.penselnsvag.bookdb.module.user.UserService;
	import se.penselnsvag.bookdb.tech.log.LogManager;
	import se.penselnsvag.bookdb.tech.rpc.DataUpdateProxy;

	public class UserTest extends TestCase
	{
		public function UserTest(methodName:String=null)
		{
			super(methodName);
		}
		
		public function testGetAllUsers():void {
			var helper:Function = addAsync(checkGetAllUsers, 2500);
			var dup:DataUpdateProxy = new DataUpdateProxy(helper, fault);
			UserService.getInstance().getAllUsers(dup);
		}
		
		private function checkGetAllUsers(re:ResultEvent):void {
			var b:User;
			var a:Array = re.result as Array;
			LogManager.getInstance().getLogger(this).debug("First name:"+User(a[0]).f_name);
		}
		
		private function fault(fe:FaultEvent):void {
			var a:Alert = new Alert();
			a.text="Message: "+fe.message+"\n";
			a.text+="Root cause: "+fe.fault.rootCause+"\n";
			PopUpManager.addPopUp(a, DisplayObject(Application.application));
		}
		
	}
}